/******************************************************************************
** 
** File name: 	utest_00.c
**	
** Description:	RTOS Ver.3 Unit Tests template source file.
**
** RTOS API Services to be checked:
**
**				- RTOS_DECLARE_TASK()
**				- RTOS_DECLARE_ISR()
**				- RTOS_DECLARE_EVENT()
**				- RTOS_DECLARE_MESSAGE()
**				- RTOS_DECLARE_MESSAGEQ()
**
**				- RTOS_EXPORT_TASK()
**				- RTOS_EXPORT_ISR()
**				- RTOS_EXPORT_EVENT()
**				- RTOS_EXPORT_MESSAGE()
**				- RTOS_EXPORT_MESSAGEQ()
**
**				- RTOS_ISR_FUNC()
**				- RTOS_TASK_FUNC()
**
**				- RTOS_Initialize()
**				- RTOS_StartOS()
**
** Notes:		This is MANUAL test!
**
*******************************************************************************
**
** Change history:
**	
** 09/25/2012 -AK- 	Introducing new unit test standard with RTOS 
**					configuration moved to the dedicated source/header file
**
******************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>

#ifndef UTEST_00
#	error "UTEST_00 must be defined as -D$(Configuration) compiler option"
#endif

#include "UTEST_RES.h"

/******************************************************************************
**	UNIT TEST INTERRUPT FUNCTION[s]
******************************************************************************/
/*
** Dummy Timer Handler
*/
RTOS_ISR_FUNC(SYS_TMR_Handler)
{
	RTOS_DEBUG_PRINT(ISR,"[ST] entering SYSTEM timer handler");
	UTST_TIMER_STOP(sys_tmr);
	RTOS_DEBUG_PRINT(ISR,"[ST] system timer stopped");
}

/*
** User' Timer Handler
*/
RTOS_ISR_FUNC(TIMER_1_Handler)
{
	RTOS_DEBUG_PRINT(ISR,"[T1] entering user timer #1 handler");
	UTST_TIMER_STOP(usr_tmr_1);
	RTOS_DEBUG_PRINT(ISR,"[T1] user timer #1 stopped");
}


RTOS_ISR_FUNC(TIMER_2_Handler)
{
	RTOS_DEBUG_PRINT(ISR,"[T2] entering user timer #2 handler");
	UTST_TIMER_STOP(usr_tmr_2);
	RTOS_DEBUG_PRINT(ISR,"[T2] user timer #2 stopped");
}

/******************************************************************************
**	UNIT TEST TASK FUNCTION[s]
******************************************************************************/
/*
** RTOS Task #0 - Stack checking task
*/
RTOS_TASK_FUNC(tsk0)
{
	RTOS_DEBUG_PRINT(TASK,"[T0] task started at %d", RTOS_GetTime());
	while (1)
	{
		RTOS_DEBUG_PRINT(TASK,"[T0] supending at %d ...", RTOS_GetTime());
		RTOS_TaskSuspend(&tsk0PID);		
	}
}

/*
** RTOS Task #1
*/
RTOS_TASK_FUNC(tsk1)
{
	RTOS_DEBUG_PRINT(TASK,"\t[T1] task started at %d", RTOS_GetTime());
	while (1)
	{
		RTOS_DEBUG_PRINT(TASK,"\t[T1] supending at %d ...", RTOS_GetTime());
		RTOS_TaskSuspend(&tsk1PID);		
	}
}

/*
** RTOS Task #2
*/
RTOS_TASK_FUNC(tsk2)
{
	RTOS_DEBUG_PRINT(TASK,"\t\t[T2] task started at %d", RTOS_GetTime());
	while (1)
	{
		RTOS_DEBUG_PRINT(TASK,"\t\t[T2] supending at %d ...", RTOS_GetTime());
		RTOS_TaskSuspend(&tsk2PID);		
	}
}

/*
** RTOS Task #4
*/
RTOS_TASK_FUNC(tsk3)
{
	RTOS_DEBUG_PRINT(TASK,"\t\t\t[T3] task started at %d", RTOS_GetTime());
	while (1)
	{
		RTOS_DEBUG_PRINT(TASK,"\t\t\t[T3] supending at %d ...", RTOS_GetTime());
		RTOS_TaskSuspend(&tsk3PID);		
	}
}

